﻿using TLogger = Beeflys.Logger;

namespace Beeflys
{
    public abstract partial class AComponent
    {
        sealed class ComponentLogger : ILogger
        {
            public ComponentLogger(AComponent component)
            {
                this.component = component;
            }

            private AComponent component;

            public bool IsEnabled(LogLevel level)
            {
                return TLogger.Current.IsEnabled(level);
            }

            public void Info(string text)
            {
                if (this.IsEnabled(LogLevel.INFO))
                    TLogger.Current.Info(this.JointLogText(text));
            }

            public void Warn(string text)
            {
                if (this.IsEnabled(LogLevel.WARN))
                    TLogger.Current.Warn(this.JointLogText(text));
            }

            public void Debug(string text)
            {
                if (this.IsEnabled(LogLevel.DEBUG))
                    TLogger.Current.Debug(this.JointLogText(text));
            }

            public void Error(string text)
            {
                if (this.IsEnabled(LogLevel.ERROR))
                    TLogger.Current.Error(this.JointLogText(text));
            }

            private string JointLogText(string text)
            {
                return $"[{this.component.Actor.Id.FullAddress}::{this.component.Name}]=>{text}";
            }
        }
    }
}